<template>
    <div>
      <!-- 审核 -->
      <div style="margin-bottom: 10px;margin-top: 10px;">
            <el-input v-model="createUserName"  placeholder="请输入产物名" suffix-icon="el-icon-search" style="width: 200px"
            @keyup.enter.native="loadPost"></el-input>
            <el-select v-model="activityId"  placeholder="请选择活动"  style="margin-left: 10px">
             <el-option
              v-for="item in activityIds"
              :key="item.value"
              :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
  
         
       
            <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
            <el-button type="success" @click="resetParam">重置</el-button>
          
        </div>
    <el-table :data="tableData"
    :header-cell-style="{background:'#f2f5fc',color:'#555'}" border>
        <el-table-column prop="id" label="ID" width="160">
        </el-table-column>
  
        <el-table-column prop="activityId" label="活动名" width="160" :formatter="titleFormate">
        </el-table-column>
   
        <el-table-column prop="achieveId" label="产物名"  width="160"  :formatter="achievementFormate">
        </el-table-column>
  
        <el-table-column prop="status" label="状态"  width="160" :formatter="statusFormate">
        </el-table-column>
  
        
  
        <el-table-column prop="createUserName" label="创建人姓名"  width="160">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间"  width="160">
        </el-table-column>
  
  
        
        <el-table-column prop="updateUserName" label="修改人姓名"  width="160">
        </el-table-column>
        <el-table-column prop="updateTime" label="修改时间"  width="160">
        </el-table-column>
  
  
        
        <el-table-column prop="operate" label="操作">
            <template slot-scope="scope">
          <el-button size="small" type="success" @click="evaluation(scope.row.id)">评为优秀</el-button>
          <el-button size="small" type="success" @click="dowm(scope.row)">下载附件</el-button>
        </template>
        </el-table-column>
  
    </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pagenum"
                :page-sizes="[2, 5, 10, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
        <el-dialog
                title="活动审核"
                :visible.sync="centerDialogVisible"
                width="80%"
                center>
        </el-dialog>
    
    </div>
  </template>
  
  <script>
      export default {
          name: "UnitList",
          data() {
           
              return {
          activityId:-1,
          activityIds:[{
              value: -1,
              label: '全部活动'
              }, {
                value: 1,
                label: '重庆财经学院第三届讯飞杯'
                  },
                  {
                value: 2,
                label: '重庆马拉松赛事'
                  },
                ],
                achieve_evaluation:1,
                ActivityData:[],
                tableData: [],
                AchievementData:[],
                pagenum:1,
                pageSize:2,
                createUserName:'',
                total:0,
                name:'',
                
                  centerDialogVisible:false,
              
  
              }
  
          },
          methods:{
              achievementFormate(row, index){
                  for(let i in this.AchievementData){
                      if(this.AchievementData[i].id==row.achieveId){
                          return this.AchievementData[i].name
                      }
                  }
              },
              titleFormate(row, index){
                  for(let i in this.ActivityData){
                      if(this.ActivityData[i].id==row.activityId){
                          return this.ActivityData[i].title
                      }
                  }
              },
                // 显示状态
             statusFormate(row, index){
                  if(row.status == 1){
                      return "筹划中";
                  }else if(row.status == 2){
                      return "已发布";
                  }else if(row.status == 3){
                      return "已下架";
                  }},
              resetForm() {
                  this.$refs.form.resetFields();
              },
           
           
            
        
              resetParam(){
                  this.createUserName='',
                  this.status=-1
             
                  
              },
              handleSizeChange(val) {
                  
                  this.pagenum=1
                  this.pageSize=val
                  this.loadPost()
              },
              handleCurrentChange(val) {
                  
                  this.pagenum=val
                  this.loadPost()
              },
            
          
              loadPost(){
               
               this.$axios.get(this.$httpUrl+'/jk/activity/apply/listT?createUserName='+this.createUserName+'&activityId='+this.activityId+'&pagenum='+this.pagenum +'&pageSize='+this.pageSize
               ).then(res=>res.data).then(res=>{
                
                   if (res.resCode=='000000'){
                       this.tableData=res.data.records
                      
                       this.total=res.data.total
  
                   }else{
                       alert('获取数据失败')
                   }
  
               })
           },
    //  获取活动
    loadActivity(){
             
             this.$axios.get(this.$httpUrl+'/jk/admin/activity/listAll').then(res=>res.data).then(res=>{
                
                 if (res.resCode=='000000'){
                     this.ActivityData=res.data
                   
                     console.log(this.ActivityData)

                 }else{
                     alert('获取数据失败')
                 }

             })
         },
  
          // 获取成果
              loadAchievement(){
               
               this.$axios.get(this.$httpUrl+'/jk/admin/achievement/listAll').then(res=>res.data).then(res=>{
                  
                   if (res.resCode=='000000'){
                       this.AchievementData=res.data
  
                   }else{
                       alert('获取数据失败')
                   }
  
               })
           },     
           evaluation(id){
            this.$axios.put(this.$httpUrl+'/jk/activity/apply/evaluation?id='+id+'&achieve_evaluation='+1).then(res=>res.data).then(res=>{
                
             
                 if (res.resCode=='000000'){
                    this.$message({
                              message: '操作成功',
                              type: 'success'
                          });  
                 }else{
                    this.$message({
                              message: '获取数据失败',
                              type: 'error'
                          });
                 }

             })
         },
         dowm(row){
     
                if(row.filePath!='-'){ window.location = "http://localhost:9001/jk/admin/activity/down?id=" + row.id;}
               else{

                this.$message({
                              message: '没有附件',
                              type: 'error'
                          });
               }
            
            },
          },
          beforeMount() {
            this.loadActivity()
             this.loadAchievement()
              this.loadPost();
  
          }
      }
  </script>
  
  <style>
  
  </style>